#
# packet template
#
# Copyright (C) 2010 by Marina Popova <marika@tusur.info>
#
# See CREDITS for details about who has contributed to this project.
#
# For further information about the pdaXrom project and license conditions
# see the README file.
#

MOTION_VERSION=3.2.11.1
MOTION=motion-${MOTION_VERSION}.tar.gz
MOTION_MIRROR=http://sourceforge.net/projects/motion/files/motion%20-%203.2
MOTION_DIR=$BUILD_DIR/motion-${MOTION_VERSION}
MOTION_ENV="$CROSS_ENV_AC"

build_motion() {
    test -e "$STATE_DIR/motion.installed" && return
    banner "Build motion"
    download $MOTION_MIRROR $MOTION
    extract $MOTION
    apply_patches $MOTION_DIR $MOTION
    pushd $TOP_DIR
    cd $MOTION_DIR
    (
    eval \
	$CROSS_CONF_ENV \
	$MOTION_ENV \
	./configure --build=$BUILD_ARCH --host=$TARGET_ARCH \
	    --prefix=/usr \
	    --sysconfdir=/etc \
	    --with-ffmpeg=${TARGET_BIN_DIR} \
	    || error
    ) || error "configure"

    make $MAKEARGS || error

    install_fakeroot_init
    install_fakeroot_finish || error

    mkdir -p ${ROOTFS_DIR}/var/run/motion
    mkdir -p ${ROOTFS_DIR}/var/www/htdocs/cams/default
    $INSTALL -D -m 644 ${BSP_GENERICFS_DIR}/motion/motion.conf ${ROOTFS_DIR}/etc/motion.conf
    $INSTALL -D -m 755 ${BSP_GENERICFS_DIR}/motion/motion.init ${ROOTFS_DIR}/etc/init.d/motion || error "install init file"
    install_rc_start motion 95
    install_rc_stop  motion 05

    popd
    touch "$STATE_DIR/motion.installed"
}

build_motion
